package com.example.clublesson01.fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.bw.kf.lib_base.base.BaseFragment
import com.bw.kf.lib_base.base.BaseViewFragment
import com.example.clublesson01.R
import com.example.clublesson01.adapter.ImageAdapter
import com.example.clublesson01.adapter.PlayCartInfoAdapter
import com.example.clublesson01.databinding.FragmentHomeBinding
import com.example.clublesson01.fragments.playcart.PlayCartViewModel
import com.flyco.tablayout.listener.CustomTabEntity
import com.youth.banner.Banner
import java.util.ArrayList


class HomeFragment : BaseFragment<FragmentHomeBinding,PlayCartViewModel>() {
    var imageList = listOf(R.drawable.img11, R.drawable.img_15)
    lateinit var adapter: ImageAdapter
    val playCartTopTabsList = ArrayList<CustomTabEntity>()
    val playCartInfoAdapter = PlayCartInfoAdapter()
    override fun iniView() {
        adapter = ImageAdapter(imageList)
        binding.banner2.setAdapter(adapter)
        binding.banner2.start()



        // 请求播放车信息列表数据，这里请求的是默认类型的数据
        viewModel.getPalyCartInfoList("0", 1, 10)
        // 设置播放车信息列表的适配器
        binding.rec.adapter = playCartInfoAdapter
        // 设置播放车信息列表的布局管理器为线性布局管理器
        binding.rec.layoutManager = LinearLayoutManager(context)
    }

    override fun iniData() {
        viewModel.playCartInfoSuccess.observe(this) {
            // 更新播放列表信息适配器的数据，并通知数据集发生变化
            //注意此处使用setNewData需要将数据源中的List集合改成MutableList setNewData不能传不可变集合
            playCartInfoAdapter.setNewData(it.data.records)
            playCartInfoAdapter.notifyDataSetChanged()
        }
    }

    override fun getViewModel(): Class<PlayCartViewModel> {
        return PlayCartViewModel::class.java
    }

    override fun Layoutid(): Int {
        return R.layout.fragment_home
    }


}